package com.neteast.androidclient.contact.domain;

import java.util.ArrayList;


public class Contact {
	
	
	//本用户的id，用于服务器
	public int ownId;
	//云好友的id，用户服务器。注，当ownId=contactId时，意味着本人修改自己在服务器上的信息
	public int contactId;
	public String localId;
	public String displayName;
	public String nickName;
	public String organization;
	public String job;
	public String photo;
	//姓名的拼音首字母
	public char sortKey;
	public boolean hasPhoto=false;
	public boolean isReadOnly=false;
	
	public String groups;
	//用于和系统数据库交互时使用
	public ArrayList<String> localGroups=new ArrayList<String>();
	
	public ArrayList<ContactData> phones=new ArrayList<ContactData>();
	public ArrayList<ContactData> emails=new ArrayList<ContactData>();
	public ArrayList<ContactData> ims=new ArrayList<ContactData>();
	public ArrayList<ContactData> locations=new ArrayList<ContactData>();
	
	public String remark;
	public String state;
	
	@Override
	public Contact clone(){
		Contact contact=new Contact();
		contact.ownId=ownId;
		contact.contactId=contactId;
		contact.localId=localId;
		contact.displayName=displayName;
		contact.nickName=nickName;
		contact.sortKey=sortKey;
		contact.organization=organization;
		contact.job=job;
		contact.photo=photo;
		contact.hasPhoto=hasPhoto;
		contact.isReadOnly=isReadOnly;
		contact.groups=groups;
		contact.phones=new ArrayList<ContactData>(copyContactData(phones));
		contact.emails=new ArrayList<ContactData>(copyContactData(emails));
		contact.ims=new ArrayList<ContactData>(copyContactData(ims));
		contact.locations=new ArrayList<ContactData>(copyContactData(locations));
		contact.remark=remark;
		contact.state=state;
		return contact;
	}
	
	private ArrayList<ContactData> copyContactData(ArrayList<ContactData> datas) {
		if (datas==null) {
			return null;
		}
		ArrayList<ContactData> contactDatas=new ArrayList<ContactData>();
		int size=datas.size();
		for(int i=0;i<size;i++){
			ContactData data = datas.get(i).clone();
			contactDatas.add(data);
		}
		return contactDatas;
	}

	@Override
	public String toString() {
		return "Contact [ownId=" + ownId + ", contactId=" + contactId
				+ ", localId=" + localId + ", displayName=" + displayName
				+ ", nickName=" + nickName + ", organization=" + organization
				+ ", job=" + job + ", photo=" + photo + ", sortKey=" + sortKey
				+ ", hasPhoto=" + hasPhoto + ", isReadOnly=" + isReadOnly
				+ ", groups=" + groups + ", localGroups=" + localGroups
				+ ", phones=" + phones + ", emails=" + emails + ", ims=" + ims
				+ ", locations=" + locations + ", remark=" + remark
				+ ", state=" + state + "]";
	}

	public void clear(){
		displayName=null;
		nickName=null;
		organization=null;
		job=null;
		photo=null;
		groups=null;
		phones.clear();
		phones=null;
		emails.clear();
		emails=null;
		ims.clear();
		ims=null;
		locations.clear();
		locations=null;
		remark=null;
		state=null;
	}
}
